package com.qgs.secsgem.mq.configuration;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2021/8/14 10:45
 */
@Configuration
public class ConfigOfDeadLetterQueue {
    /**
     * 队列默认参数：
     *      durable:    true
     *      exclusive:  false
     *      autoDelete: false
     */

    /**
     * 死信队列 定义
     *
     * 所以 MES-Received 处理异常的 Message 都会被 投递到 Dead_Letter_Exchange => Dead_Letter_Queue(这个队列)
     */
    public static final String EXCHANGE_NAME_DLE = "Dead_Letter_Exchange";
    public static final String Dead_Letter_Queue = "Dead_Letter_Queue";
    public static final String Dead_Letter_RoutingKey = "Dead_Letter_RoutingKey";
    public static final Integer MAX_PRIORITY = 10;

    @Bean
    public Queue EAP_REQUEST_QUEUE_DLE(){
        Queue queue = new Queue(Dead_Letter_Queue);
        queue.setIgnoreDeclarationExceptions(true);
        
        return queue;
    }

    @Bean
    public DirectExchange EXCHANGE_NAME_DLE(){
        return new DirectExchange(EXCHANGE_NAME_DLE);
    }

    @Bean
    public Binding EAP_REQUEST_QUEUE_ROUTINGKEY_DLE(){
        return BindingBuilder.bind(EAP_REQUEST_QUEUE_DLE()).to(EXCHANGE_NAME_DLE())
                .with(Dead_Letter_RoutingKey);
    }
}
